package com.yxp.easy.permissionutil;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.yxp.easy.permissionutil.adapter.base.DividerItemDecoration;
import com.yxp.easy.permissionutil.adapter.inter.IndexAdapter;
import com.yxp.easy.permissionutil.adapter.listener.OnItemClickListener;
import com.yxp.easy.permissionutil.adapter.listener.OnItemLongClickListener;

import java.util.ArrayList;

import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler2;
import in.srain.cube.views.ptr.PtrFrameLayout;

/**
 * Created by Administrator on 2016/4/19.
 */
public class IndexActivity extends BaseActivity {
    RecyclerView indexRecyclerView;
    PtrClassicFrameLayout mPtrFrame;
    IndexAdapter indexAdapter;
    ArrayList<Indo> mIndos = new ArrayList<>();

    @Override
    public void onNext(View view) {
        Toast.makeText(IndexActivity.this, "T", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.index);
        Toolbar id_toolbar = (Toolbar) findViewById(R.id.id_toolbar);
        TextView index_tv_title = (TextView) findViewById(R.id.index_tv_title);
        index_tv_title.setText(getResources().getString(R.string.str_index));
        ImageView index_iv_right = (ImageView) findViewById(R.id.index_iv_right);
        index_iv_right.setVisibility(View.GONE);
        id_toolbar.setTitle("");
        setSupportActionBar(id_toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        id_toolbar.setNavigationIcon(R.mipmap.ic_info);
        id_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(IndexActivity.this, "T", Toast.LENGTH_SHORT).show();
            }
        });
        for (int i = 0; i < 20; i++) {
            mIndos.add(new Indo());
        }
        indexRecyclerView = (RecyclerView) findViewById(R.id.index_recycler_view);
        mPtrFrame = (PtrClassicFrameLayout) findViewById(R.id.rotate_header_list_view_frame);
        mPtrFrame.setLastUpdateTimeRelateObject(this);
        mPtrFrame.setPtrHandler(new PtrDefaultHandler2() {

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                // TODO Auto-generated method stub
                mPtrFrame.refreshComplete();
            }

            @Override
            public void onLoadMoreBegin(PtrFrameLayout frame) {
                // TODO Auto-generated method stub
                mPtrFrame.refreshComplete();
            }

        });
        // the following are default settings
        mPtrFrame.setResistance(1.7f);
        mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
        mPtrFrame.setDurationToClose(200);
        mPtrFrame.setDurationToCloseHeader(1000);
        // default is false
        mPtrFrame.setPullToRefresh(false);
        // default is true
        mPtrFrame.setKeepHeaderWhenRefresh(true);
        indexAdapter = new IndexAdapter(mIndos);
        indexAdapter.setOnItemClickListener(new OnItemClickListener<Indo>() {

            @Override
            public void onClick(View view, Indo item) {

            }
        });

        indexAdapter.setOnItemLongClickListener(new OnItemLongClickListener<Indo>() {
            @Override
            public void onLongClick(View view, Indo item) {
            }
        });
        indexRecyclerView.setHasFixedSize(true);//固定大小
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        indexRecyclerView.setLayoutManager(linearLayoutManager);
        //间隔线条
        indexRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
        indexRecyclerView.setAdapter(indexAdapter);

    }
}
